// pages/addEquipment/addEquipment.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    customer_code: '', //户号
    equipment: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    that.getNumber();
  },

  //确认事件 缴费器信息
  affirmfun(e) {
    var that = this;
    var customer_code = e.detail.value.customer_code;
    if (customer_code == '') {
      app.showToast('请输入户号');
      return false;
    }
    var pattern1 = /^[A-Za-z0-9]+$/;
    if (!pattern1.test(customer_code) && customer_code != "") {
      app.showToast('您输的户号格式不正确哟~');
      return false;
    }
    app.ajax({
      url: 'User/Equipmentlists/addEquipment',
      data: { customer_code },
      success: function (res) {
        app.showToast(res.data.message);
        if (res.data.code == 1000) {
          setTimeout(()=>{
            wx.navigateBack();
          },1000)
        }
      }
    })
  },
  // 获取测试户号
  getNumber: function() {
    var that = this;
    app.ajax({
      url: 'Common/Test/bindDeviceNo',
      data: {},
      success: function(res) {
        if (res.data.code == 1000) {
          that.setData({
            equipment: res.data.data
          })
        }
      }
    })
  },
  //复制户号
  copy(e) {
    var that = this;
    var serialnum = e.currentTarget.dataset.serialnum;
    wx.setClipboardData({
      data: serialnum,
      success: function(res) {
        wx.getClipboardData({
          success: function(res) {
            that.setData({
              customer_code: serialnum
            })
          }
        })
      }
    })
  },
  //去商城
  goShop() {
    wx.switchTab({
      url: '../shopping/shoppingHome/shoppingHome'
    })
  }
})
